package com.dormitoryAdministratorSystem.ui.roommanage;

import com.dormitoryAdministratorSystem.entity.room.RoomBean;
import com.dormitoryAdministratorSystem.service.room.impl.RoomSerImpl;
import com.dormitoryAdministratorSystem.ui.MainFrame;
import com.dormitoryAdministratorSystem.util.BeansUtil;
import com.lovo.netCRM.component.LovoButton;
import com.lovo.netCRM.component.LovoLabel;
import com.lovo.netCRM.component.LovoTable;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class RoomInfoDialog extends JDialog {
	
	private LovoLabel roomAddressLab;
	private LovoLabel buildingTypeLab;//户型	
	private LovoLabel capNumLab;//可容纳人数
	private LovoLabel inNumLab;//已住人数	
	private LovoLabel rentPriceLab;
	private LovoLabel payTypeLab;
	private LovoLabel roomHostLab;//房东
	private LovoLabel hostTelLab;
	private LovoLabel roomStatusLab;//房间状态
	private LovoLabel roomTypeComb;
	private LovoLabel rentDateLab;
	
	private LovoTable stuTab;
	
	private LovoButton confirmBtn;

	private int id;

	private RoomSerImpl rsi = new RoomSerImpl();
	
	
	public RoomInfoDialog(MainFrame frame, int id) {
		// TODO Auto-generated constructor stub
		super(frame,"房间信息",true);
		this.id = id;
		this.setBounds(350, 250, 520, 480);
		this.setLayout(null);
		this.init();
		this.initTable();
		
		this.setVisible(true);
	}

	private void init() {
		// TODO Auto-generated method stub
		this.roomAddressLab = new LovoLabel("房间地址",20, 20, this);
		this.buildingTypeLab = new LovoLabel("房间户型",270, 20, this);
		this.capNumLab = new LovoLabel("可容纳人数",20, 60, this);
		this.inNumLab = new LovoLabel("已住人数",270, 60, this);
		this.rentPriceLab = new LovoLabel("房租",20, 100, this);
		this.payTypeLab = new LovoLabel("支付方式",270, 100, this);
		this.roomStatusLab = new LovoLabel("房间状态",20, 140, this);
		this.roomTypeComb = new LovoLabel("房间类型",270, 140, this);
		this.rentDateLab = new LovoLabel("租房日期",20, 180, this);

		RoomBean r = rsi.getRoomInfo(RoomInfoDialog.this.id);
		roomAddressLab.setText(r.getAddress());
		capNumLab.setText(r.getSize()+"");
		roomStatusLab.setText(r.getRoomState());
		rentPriceLab.setText(r.getRent()+"");
		rentDateLab.setText(r.getRentTime().toString());
		inNumLab.setText(r.getPeopleNo()+"");
		payTypeLab.setText(r.getPayMode());
		buildingTypeLab.setText(r.getHouseType());
		roomTypeComb.setText(r.getRoomType());

		this.confirmBtn = new LovoButton("确定", 220, 390, this);
		this.confirmBtn.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				RoomInfoDialog.this.dispose();
			}
		});
	}
	
	private void initTable() {
		// TODO Auto-generated method stub
		this.stuTab = new LovoTable(this, new String[]{"学生姓名","所在班级","联系电话"},
				new String[]{"sName", "classBean.cName", "phoneNum"},//数组中应该是对应属性的属性名
				"sId");//填入唯一标示属性
		this.stuTab.setSizeAndLocation(20, 220, 480, 150);
		this.stuTab.updateLovoTable(BeansUtil.getStudents(this.id));
	}
}
